#include <stdio.h>
#include <dpmi.h>
#include <stdlib.h> //para o system

#include "utypes.h"
#include "video.h"
#include "pixmap.h"
#include "sprite.h"
#include "asprite.h"





int main()
{


/* Possible sprite types:
** 1: normal waterlily
** 2: start waterlily
** 3: goal waterlily
** 4: egg
************************/

/* Possible graphical modes:
** MODE_1: 640x480
** MODE_3: 800x600
** MODE_5: 1024x768
** MODE_7: 1280x1024
***************************/


	__dpmi_meminfo map; //generic pointer for memory access
	char * video_addr; //stores the video memory address


	
	//enters graphic mode 800x600 (MODE_3)
	video_addr = enter_graphics(MODE_3, &map);

	//draws the lake
	draw_background(video_addr);
	
	//draws the base waterlilies
	draw_fixed_sprites(video_addr);
	
	
	
	
	void draw_waterlilies(char *base)
	{
		int lin, col, x = BASE_X, y = BASE_Y;
		Sprite *lily_xxl, *lily_xxs;
		

		//drawing of the "matrix", with the xxl waterlilies
		for (lin = 0; lin < LINES; lin++){
			
			for (col = 0; col < COLUMNS; col++){
				
				//creation of the waterlily instance, with a default position,
				//type normal (1), and visible (1).
				lily_xxl = create_sprite(waterlily_xxl, NORMAL, x, y, VISIBLE);
				lily_xxs = create_sprite(waterlily_xxs, NORMAL, x + (lily_xxl->width / 2), y + (lily_xxl->height / 2), VISIBLE);
				
				//draw_sprite(lily_xxl, lily_xxl->x, lily_xxl->y, base);
				draw_sprite(lily_xxs, lily_xxs->x - (lily_xxs->width / 2), lily_xxs->y - (lily_xxs->height / 2), base);
				
				x += BASE_X * 2; 
			}
			
			x = BASE_X; //reset of the x coordinate
			
			y += BASE_Y * 2;
		}
		
	}
	
	
	//draws the base matrix of the waterlilies
	draw_waterlilies(video_addr);
	
	int x, y;
	Sprite *start_lily;
	start_lily = create_sprite(waterlily_xxl, START, x, y, INVISIBLE);
	
	//placing of the frog at the starting position
	move_sprite(start_lily, 0, video_addr);
	
	//move_cursor(0, 0, video_addr);
	
	system("pause");
	
	start_lily->type = NORMAL;
	
	move_sprite(start_lily, RIGHT_ARROW, video_addr);
	
	//move_cursor(350, 225, video_addr);
	
	
	/*
	Sprite *sapo = create_sprite(frog, 1, 45, 60, 1);
	Sprite *ovo_ouro = create_sprite(golden_egg, 1, 90, 60, 1);
	Sprite *lily_xxs = create_sprite(waterlily_xxs, 1, 200, 60, 1);
	Sprite *lily_xs = create_sprite(waterlily_xs, 1, 200, 60, 1);
	Sprite *lily_s = create_sprite(waterlily_s, 1, 200, 60, 1);
	Sprite *lily_m = create_sprite(waterlily_m, 1, 200, 60, 1);
	Sprite *lily_l = create_sprite(waterlily_l, 1, 200, 60, 1);
	Sprite *lily_xl = create_sprite(waterlily_xl, 1, 200, 60, 1);
	Sprite *lily_xxl = create_sprite(waterlily_xxl, 1, 200, 60, 1);
	Sprite *splashh = create_sprite(splashh, 1, 200, 60, 1);
	
	draw_sprite(sapo, 10, 60, video_addr);
	draw_sprite(ovo_ouro, 50, 60, video_addr);
	draw_sprite(lily_xxs, 100, 60, video_addr);
	draw_sprite(lily_xs, 200, 60, video_addr);
	draw_sprite(lily_s, 300, 60, video_addr);
	draw_sprite(lily_m, 400, 60, video_addr);
	draw_sprite(lily_l, 500, 60, video_addr);
	draw_sprite(lily_xl, 600, 60, video_addr);
	draw_sprite(lily_xxl, 700, 60, video_addr);
*/
	
	system("pause");

	
	//leaves graphic mode, returning to text mode
	leave_graphics(map);
	
	return 0;
	
} //end main
